package com.corpgovernment.supplier.util;


import com.corpgovernment.common.common.CorpBusinessException;
import com.corpgovernment.common.enums.ExceptionCodeEnum;
import com.corpgovernment.organization.constant.OrganizationResponseCodeEnum;
import org.springframework.validation.Errors;
import org.springframework.validation.ObjectError;

import java.util.List;

/**
 * Created by liubk on 2019/6/3.
 */
public class ParamValidator {

    public static void validParam(Errors errors) {
        if (errors.hasErrors()) {
            List<ObjectError> error = errors.getAllErrors();
            StringBuilder validMsgBuilder = new StringBuilder();
            for (ObjectError objectError : error) {
                validMsgBuilder.append("[").append(objectError.getDefaultMessage()).append("]");
            }
            throw  new CorpBusinessException(OrganizationResponseCodeEnum.CUSTOM_CONTENT,validMsgBuilder.toString());
        }
    }
}